//
//  AFNHttpRequest.m
//  EASMobile
//
//  Created by wendy on 15/8/12.
//  Copyright (c) 2015年 ABB. All rights reserved.
//

#import "AFNHttpRequest.h"
#import "NetworkConfig.h"


@implementation AFNHttpRequest
+ (void)afnHttpRequestUrl:(NSString *)requestInterface param:(NSDictionary *)param success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure
{

    NSString *url = [NSString stringWithFormat:@"%@%@", kHttpIPAddress, requestInterface];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", nil];
    
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    

    [manager POST:url parameters:param progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"请求成功");
        
       //  先转成NSDictionary
                       NSDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:(NSData *)responseObject
                                                                                    options:NSJSONReadingMutableContainers
                                                                                      error:nil];
                       success(responseDict);
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
       // failure(error);
            NSLog(@"网络请求失败:%ld", (long)error.code);
    }];

}

@end
